package org.come.thread;

import com.tool.ModerateTask.*;
import com.tool.image.ImageMixDeal;
import com.tool.image.ManimgAttribute;
import com.tool.imagemonitor.*;
import com.tool.time.TimeLimit;
import come.tool.Fighting.FightingMixDeal;
import come.tool.FightingData.FightingForesee;
import come.tool.map.XLPath;
import org.apache.commons.lang.StringUtils;
import org.come.Frame.NPCJfram;
import org.come.Frame.ZhuFrame;
import org.come.Jpanel.WorldMapJpanel;
import org.come.action.MapAction;
import org.come.bean.RoleShow;
import org.come.entity.Goodstable;
import org.come.model.AutoTaskBase;
import org.come.model.Door;
import org.come.mouslisten.GoodsMouslisten;
import org.come.mouslisten.Mouselistener;
import org.come.npc.TP;
import org.come.socket.Agreement;
import org.come.socket.SendMessageUntil;
import org.come.until.*;

import java.util.ArrayList;
import java.util.List;

public class AutoTaskTimeControlRunnable implements Runnable {
    private int jg=0;
    private int tx=0;
    private static boolean isScript=false;
    private static boolean isAutoTask = false;

    public static boolean isIsAutoTask() {
        if(isAutoTask || isScript ||(autoTaskBaseList!=null && autoTaskBaseList.size()>0)){
            return true;
        }else return false;
    }

    public static void setIsAutoTask(boolean isAutoTask) {
        AutoTaskTimeControlRunnable.isAutoTask = isAutoTask;
    }

    private static final Object object=new Object();

    @Override
    public void run() {
        while (true) {
            try {
                long x=System.currentTimeMillis();
                int cha=25;
                if (FightingMixDeal.State==0){
                    tx=6;
                    cha=150;
                }else {
                    tx++;
                }
                if (tx>5) {
                    tx=0;
                    CommonUse();
                }

                x=System.currentTimeMillis()-x;
                if (x<cha){
                    Thread.sleep(cha-x);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    /**通用处理*/
    public void CommonUse(){
        jg++;
        if (isScript&&jg%4==0) {
            scriptHandle();
        }

        if(jg%6==0){
            addAutoTaskExt();
        }
    }
    /**脚本处理*/
    public void scriptHandle(){
        synchronized (object) {
            int size=script.size();
            if(size==0 && autoTaskBaseList==null){
                isAutoTask = false;
            }
            if (size==0) {
                isScript=false;
                return;
            }
            size-=1;
            Object object=script.get(size);
            if (object==null) {script.remove(size);return;}
            if (object instanceof ScriptOpen) {
                boolean isSuccess = true;
                 //0寻路  1点击NPC  2点击野怪  3选择传送选项  4是点击自定义野怪
                ScriptOpen open=(ScriptOpen) object;
                if (open.getType()==0) {
                    Mouselistener.XL(open.getX()/20, open.getY()/20);
                }else if (open.getType()==1) {
                    ManimgAttribute attribute=ImageMixDeal.getNpc(open.getNpc()+"");
                    if (attribute!=null) {
                        NpcMonitor.npc(attribute);
                    }
                }else if (open.getType()==2) {
                    ManimgAttribute attribute=ImageMixDeal.getTask(open.getNpc());
                    if (attribute!=null) {
                        TaskMonitor.TaskCreeps(attribute.getTaskdata());
                    }
                }else if (open.getType()==3) {
                    Door door=UserMessUntil.getDoor(open.getDoor()+"");
                    if (door!=null) {
                        TP.tp(door, 3);
                    }
                    FormsManagement.HideForm(27);
                }else if (open.getType()==101) {//传送指定位置
                    TP.tp(open.getDoor(),open.getX(),open.getY());
                }else if (open.getType()==102) {//领取任务id
                    if(NPCJfram.getNpcJfram().getNpcjpanel().getNpcInfoBean() == null){
                        isSuccess = false;
                    }else {
                        TaskMixDeal.isoption(open.getNpc(), null, NPCJfram.getNpcJfram().getNpcjpanel().getNpcInfoBean().getNpctable().getNpcway());
                        FormsManagement.HideForm(27);
                    }
                }else if (open.getType()==103) {//攻击NPC 或者 任务怪
                    MapAction.npcmenuAction.get(NpcMenuUntil.getMenu48()).menuControl("我是来击杀你的");
                    FormsManagement.HideForm(27);
                }else if (open.getType()==104) {//攻击野怪
                    ManimgAttribute tmanimgAttribute = null;
                    List<ManimgAttribute> manimgAttributeList =  ImageMixDeal.mapMonsterlist;
                    if(manimgAttributeList!=null && manimgAttributeList.size()>0){
                        for(ManimgAttribute manimgAttribute:manimgAttributeList){
                            if(manimgAttribute!=null && manimgAttribute.getMapMonsterBean()!=null && manimgAttribute.getMapMonsterBean().getI() == open.getNpc()){
                                tmanimgAttribute = manimgAttribute;
                                break;
                            }
                        }
                    }
                    if(tmanimgAttribute !=null ){
                        FightingForesee fightingForesee = new FightingForesee();
                        fightingForesee.setType(1);
                        int robotid = tmanimgAttribute.getMapMonsterBean().getRobotid();
                        RoleShow roleShow =ImageMixDeal.userimg.getRoleShow();
                        if (robotid == 651 || robotid == 8000) {
                            if (roleShow.getTeam().split("\\|").length > 1) {
                                ZhuFrame.getZhuJpanel().addPrompt2("只能单人击杀");
                                return;
                            }

                            fightingForesee.setType(4);
                        }

                        String team = roleShow.getTeam();
                        if (team.split("\\|")[0].equals(roleShow.getRolename())) {
                            fightingForesee.setI(tmanimgAttribute.getMapMonsterBean().getI());
                            fightingForesee.setYidui(team);
                            roleShow.getPlayer_Paths().clear();
                            String sendMes = Agreement.FightingForeseeAgreement(GsonUtil.getGsonUtil().getgson().toJson(fightingForesee));
                            SendMessageUntil.toServer(sendMes);
                        }
                    }
                    FormsManagement.HideForm(27);
                }else if (open.getType()==105) {//攻击NPC 或者 任务怪
                    TaskMixDeal.isoptionTaskId(open.getNpc(),null,NPCJfram.getNpcJfram().getNpcjpanel().getNpcInfoBean().getNpctable().getNpcway());
                    FormsManagement.HideForm(27);
                }
                if(isSuccess){
                    script.remove(size);
                }
            }else if (object instanceof ScriptEnd) {
                ScriptEnd end=(ScriptEnd) object;
                if (end.getType()==0) {
                    RoleShow show=ImageMixDeal.userimg.getRoleShow();
                    if (show.getMapid().intValue()==end.getMap()&&Math.abs(show.getX()-end.getX())<200&&Math.abs(show.getY()-end.getY())<200) {
                        script.remove(size);
                    }
                }
            }
        }
    }

    public void addAutoTaskExt(){
        synchronized (object) {
            if(autoTaskBaseList!=null){
                int size=autoTaskBaseList.size();
                if (size>0&&isScript==false&&(script==null || script.size()<=0) && FightingMixDeal.State ==0) {
                    size -= 1;
                    AutoTaskBase autoTaskBase = autoTaskBaseList.get(size);
                    if (autoTaskBase == null) {
                        autoTaskBaseList.remove(size);
                        return;
                    }
                    String guide = autoTaskBase.getGuide();
                    String[] v = guide.split("\\|");

                    ScriptTask scriptTask = new ScriptTask();
                    scriptTask.setSum(autoTaskBase.getAutoNum());
                    if (v.length >= 4) {
                        scriptTask.setTaskSetID(autoTaskBase.getSid());
                        scriptTask.setMap(Integer.parseInt(v[0]));
                        scriptTask.setX(Integer.parseInt(v[1]));
                        scriptTask.setY(Integer.parseInt(v[2]));
                        scriptTask.setNpcID(Integer.parseInt(v[3]));
                    }
                    if (v.length == 5) {
                        if (StringUtils.isNotBlank(v[4]) && v[4].startsWith("系统野怪设置")) {
                            String[] yg = v[4].split("=");
                            if(yg.length == 5){
                                scriptTask.setYgRobotId(Integer.valueOf(yg[1]));
                                scriptTask.setYgMapId(Integer.valueOf(yg[2]));
                                scriptTask.setYgX(Integer.valueOf(yg[3]));
                                scriptTask.setYgY(Integer.valueOf(yg[4]));
                            }
                        } else if (StringUtils.isNotBlank(v[4]) && v[4].startsWith("任务ID")) {
                            String[] tkId = v[4].split("=");
                            if(tkId.length == 2){
                                scriptTask.setTaskIdExt(Integer.valueOf(tkId[1]));
                            }
                        }
                    }
                    removeScript();//清理之前的脚本纪录
                    AutoTaskTimeControlRunnable.scriptTask = null;//清空之前的自动任务模式
                    Task task = Hero.getHero().getSetTask(scriptTask.getTaskSetID());//根据任务系列id 获取人物身上的任务
                    if (task != null) {//如果人物身上有这个任务
                        AutoTaskTimeControlRunnable.scriptTask = scriptTask;//set 自动任务模式
                        //if (task.getTaskState()!=TaskState.finishTask) {//完成任务
                            TaskProgress progress=task.getTaskProgress();
                            if (progress==null||progress.getMap()==0) {
                                //如果不在这个地图
                                RoleShow roleShow = ImageMixDeal.userimg.getRoleShow();
                                if (scriptTask != null && scriptTask.getYgMapId() != 0) {
                                    if (roleShow.getMapid() != scriptTask.getYgMapId()) {
                                        passYgMap();    //传送到地图
                                    } else {
                                        addYgScritpt(task.getProgress().get(0).getDId());     //开始杀怪
                                    }
                                }
                            }else {
                                upTask(task, task.getTaskState());//调用自动任务模式处理
                            }
                        //}else{
                        //    upTask(task, task.getTaskState());//调用自动任务模式处理
                        //}
                    } else {
                        if(scriptTask.getNpcID() > 0 ){
                            //如果人物身上没有这个任务生成脚本 前往领取任务
                            RoleShow roleShow = ImageMixDeal.userimg.getRoleShow();
                            boolean falg = GoodsListFromServerUntil.istype(2125, 1);
                            List<Object> list = null;
                            boolean mst = mustPassPort(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), scriptTask.getX(), scriptTask.getY(), scriptTask.getMap());
                            if (falg && mst) {
                                TP.tp(scriptTask.getMap(),scriptTask.getX(),scriptTask.getY());//不需要任我行
//                                autoPassPort(scriptTask.getMap() + ",1," + scriptTask.getX() + "," + scriptTask.getY());//需要任我行
                                list = XLPath.ZDXL(scriptTask.getX(), scriptTask.getY(), scriptTask.getMap(), scriptTask.getX(), scriptTask.getY(), scriptTask.getMap());
                            } else {
                                list = XLPath.ZDXL(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), scriptTask.getX(), scriptTask.getY(), scriptTask.getMap());
                            }
                            if (list == null) {
                                ZhuFrame.getZhuJpanel().addPrompt2("你所在位置无法达到目的地");
                                return;
                            }
                            ScriptOpen open = new ScriptOpen(1);
                            open.setNpc(scriptTask.getNpcID());
                            list.add(0, open);

                            if(scriptTask.getTaskIdExt()>0){
                                ScriptOpen openTwo = new ScriptOpen(105);
                                openTwo.setNpc(scriptTask.getTaskIdExt());
                                list.add(0, openTwo);
                            }else{
                                ScriptOpen openTwo = new ScriptOpen(102);
                                openTwo.setNpc(scriptTask.getTaskSetID());
                                list.add(0, openTwo);
                            }
                            AutoTaskTimeControlRunnable.scriptTask = scriptTask;
                            AutoTaskTimeControlRunnable.addScript(list);
                        }else{
                            AutoTaskTimeControlRunnable.scriptTask = scriptTask;
                            //如果不需要领取任务
                            //如果不在这个地图
                            RoleShow roleShow =ImageMixDeal.userimg.getRoleShow();
                            if(scriptTask!=null && scriptTask.getYgMapId()!=0){
                                if(roleShow.getMapid()!=scriptTask.getYgMapId()){
                                    passYgMap();    //传送到地图
                                }else{
                                    addYgScritpt(scriptTask.getYgRobotId());     //开始杀怪
                                }
                            }

                        }
                    }

                }else{
                    isAutoTask = false;
                }
            }
        }
    }


    private static List<Object> script;
    private static ScriptTask scriptTask;//任务处理


    private static List<AutoTaskBase> autoTaskBaseList;

    public static void addAutoTaskBaseList( List<AutoTaskBase> atblist){
        autoTaskBaseList = atblist;
        isAutoTask = true;
    }
    public static void addTask(ScriptTask scriptTask){
        synchronized (object) {
            removeScript();//清理之前的脚本纪录
            AutoTaskTimeControlRunnable.scriptTask=null;//清空之前的自动任务模式
            Task task=Hero.getHero().getSetTask(scriptTask.getTaskSetID());//根据任务系列id 获取人物身上的任务
            if (task!=null) {//如果人物身上有这个任务
                AutoTaskTimeControlRunnable.scriptTask=scriptTask;//set 自动任务模式
                upTask(task, task.getTaskState());//调用自动任务模式处理
            }else {//如果人物身上没有这个任务
                //生成脚本 前往领取任务
                RoleShow roleShow =ImageMixDeal.userimg.getRoleShow();
                boolean falg = GoodsListFromServerUntil.istype(2125,1);
                List<Object> list = null;
                boolean mst = mustPassPort(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), scriptTask.getX(), scriptTask.getY(), scriptTask.getMap());
                if(falg && mst) {
                    TP.tp(scriptTask.getMap(),scriptTask.getX(),scriptTask.getY());//不需要任我行
//                    autoPassPort(scriptTask.getMap()+",1,"+scriptTask.getX()+","+scriptTask.getY());//需要任我行
                    list=XLPath.ZDXL(scriptTask.getX(),scriptTask.getY(),scriptTask.getMap(),scriptTask.getX(),scriptTask.getY(),scriptTask.getMap());
                }else{
                    list=XLPath.ZDXL(roleShow.getX(),roleShow.getY(),roleShow.getMapid().intValue(),scriptTask.getX(),scriptTask.getY(),scriptTask.getMap());
                }
                if (list==null) {
                    ZhuFrame.getZhuJpanel().addPrompt2("你所在位置无法达到目的地");
                    return;
                }
                ScriptOpen open=new ScriptOpen(1);
                open.setNpc(scriptTask.getNpcID());
                list.add(0,open);

                ScriptOpen openTwo=new ScriptOpen(102);
                openTwo.setNpc(scriptTask.getTaskSetID());
                list.add(0,openTwo);

                AutoTaskTimeControlRunnable.scriptTask=scriptTask;
                AutoTaskTimeControlRunnable.addScript(list);
            }
        }
    }
    public static void upTask(Task task,int state){
        synchronized (object) {
            //自动任务模式为空 或者 自动任务模式系列id 不同 退出
            if (scriptTask==null||scriptTask.getTaskSetID()!=task.getTaskData().getTaskSetID()) {return;}
            //状态是应超时取消任务  或者 取消任务   清空自动任务模式  退出
            if (state==TaskState.quxiaoTime||state==TaskState.quxiao) {scriptTask=null;return;}
            //如果你是队员  清空自动任务模式  退出
            if (ImageMixDeal.userimg.getTeams()==null) {scriptTask=null;return;}
            if (state==TaskState.finishTask && autoTaskBaseList!=null) {//完成任务

                //回归接下一个任务  生成脚本
                List<Object> list=new ArrayList<>();
                ScriptOpen openDoor=new ScriptOpen(101);
                openDoor.setDoor(scriptTask.getMap());
                openDoor.setX(scriptTask.getX());openDoor.setY(scriptTask.getY());
                list.add(0,openDoor);

                ScriptEnd endDoor=new ScriptEnd(0,openDoor.getDoor(),openDoor.getX(),openDoor.getY());
                list.add(0,endDoor);
                list.add(null);list.add(null);//卡2个执行判断

                int size = autoTaskBaseList.size();
                size -= 1;
                autoTaskBaseList.get(size).setAutoNum(autoTaskBaseList.get(size).getAutoNum()-1);
                if(autoTaskBaseList.get(size).getAutoNum()<=0){
                    autoTaskBaseList.remove(size);
                }

                if (scriptTask.upSum()<=1) {
                    scriptTask=null;
//                    AutoTaskTimeControlRunnable.addScript(list);
                    return;
                }
                ScriptOpen open=new ScriptOpen(1);
                open.setNpc(scriptTask.getNpcID());
                list.add(0,open);

                ScriptOpen openTwo=new ScriptOpen(102);
                openTwo.setNpc(scriptTask.getTaskSetID());
                list.add(0,openTwo);
                AutoTaskTimeControlRunnable.addScript(list);


            }else {//判断任务条件 生成脚本
                TaskProgress progress=task.getTaskProgress();
                if (progress!=null&&progress.getMap()!=0) {
                    RoleShow roleShow =ImageMixDeal.userimg.getRoleShow();
                    boolean falg = GoodsListFromServerUntil.istype(2125,1);
                    List<Object> list = null;
                    boolean mst = mustPassPort(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), progress.getX(), progress.getY(), progress.getMap());
                    if(falg && mst) {
//                        TP.tp(progress.getMap(),progress.getX(),progress.getY());
                        autoPassPort(progress.getMap()+",1,"+progress.getX()+","+progress.getY());
                        list=XLPath.ZDXL(progress.getX(),progress.getY(),progress.getMap(),progress.getX(),progress.getY(),progress.getMap());
                    }else{
                        list=XLPath.ZDXL(roleShow.getX(),roleShow.getY(),roleShow.getMapid().intValue(),progress.getX(),progress.getY(),progress.getMap());
                    }

                    if (list==null) {
                        ZhuFrame.getZhuJpanel().addPrompt2("你所在位置无法达到目的地");
                        return;
                    }
                    ScriptOpen open=new ScriptOpen(progress.getType()==1?2:1);
                    open.setNpc(progress.getDId());
                    list.add(0, open);
                    if (progress.getType()==1||progress.getType()==2) {
                        //击杀NPC
                        ScriptOpen openTwo=new ScriptOpen(103);
                        openTwo.setNpc(progress.getDId());
                        list.add(0,openTwo);
                    }
                    AutoTaskTimeControlRunnable.addScript(list);
                }
            }
        }
    }

    public static void passYgMap() {
        RoleShow roleShow = ImageMixDeal.userimg.getRoleShow();
        boolean mst = mustPassPort1(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), scriptTask.getYgX(), scriptTask.getYgY(), scriptTask.getYgMapId());
        boolean falg = GoodsListFromServerUntil.istype(2125,1);
        List<Object> list = null;
        if (falg && mst) {
//            TP.tp(scriptTask.getYgMapId(),scriptTask.getYgX(),scriptTask.getYgY());
            autoPassPort(scriptTask.getYgMapId() + ",1," + scriptTask.getYgX() + "," + scriptTask.getYgY());
        } else {
            list = XLPath.ZDXL(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), scriptTask.getYgX(), scriptTask.getYgY(), scriptTask.getYgMapId());
            if (list == null) {
                ZhuFrame.getZhuJpanel().addPrompt2("你所在位置无法达到目的地");
                return;
            }
            AutoTaskTimeControlRunnable.addScript(list);
        }
    }

    public static void addYgScritpt(int taskDid){
        synchronized (object) {
            List<ManimgAttribute> manimgAttributeList = ImageMixDeal.mapMonsterlist;
            RoleShow roleShow = ImageMixDeal.userimg.getRoleShow();
            if (manimgAttributeList != null && manimgAttributeList.size() > 0) {
                int distance = 0;
                int cidx = -1;
                for (int i = 0; i < manimgAttributeList.size(); i++) {
                    ManimgAttribute manimgAttribute = manimgAttributeList.get(i);
                    if (manimgAttribute.getMapMonsterBean().getRobotid() == taskDid) {
                        int cdistance = XLPath.calcD(roleShow.getX(), roleShow.getY(), manimgAttribute.getX(), manimgAttribute.getY());
                        if (cidx == -1) {
                            distance = cdistance;
                            cidx = 0;
                        } else if (distance > cdistance) {
                            distance = cdistance;
                            cidx = i;
                        }
                    }
                }
                if (cidx >= 0) {
                    ManimgAttribute tmanimgAttribute = manimgAttributeList.get(cidx);
                    boolean mst = mustPassPort1(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), scriptTask.getYgX(), scriptTask.getYgY(), scriptTask.getYgMapId());
                    boolean falg = GoodsListFromServerUntil.istype(2125,1);
                    List<Object> list = null;
                    if (falg && mst) {
                        TP.tp(scriptTask.getYgMapId(),scriptTask.getYgX(),scriptTask.getYgY());
                        autoPassPort(scriptTask.getYgMapId() + ",1," + scriptTask.getYgX() + "," + scriptTask.getYgY());
                    } else {
                        list = XLPath.ZDXL(roleShow.getX(), roleShow.getY(), roleShow.getMapid().intValue(), tmanimgAttribute.getX(), tmanimgAttribute.getY(), roleShow.getMapid().intValue());
                        if (list == null) {
                            ZhuFrame.getZhuJpanel().addPrompt2("你所在位置无法达到目的地");
                            return;
                        }

                    Integer i = tmanimgAttribute.getMapMonsterBean().getI();
                    ScriptOpen openTwo=new ScriptOpen(0);
                    openTwo.setNpc(taskDid);
                    openTwo.setY(tmanimgAttribute.getY());
                    openTwo.setX(tmanimgAttribute.getX());
                    list.add(0,openTwo);
                    //击杀NPC
                    ScriptOpen openTwo1=new ScriptOpen(104);
                    openTwo1.setNpc(i);
                    list.add(0,openTwo1);

                        AutoTaskTimeControlRunnable.addScript(list);
                        Task task = Hero.getHero().getSetTask(scriptTask.getTaskSetID());
                        if(task==null){
                            int size = autoTaskBaseList.size();
                            size -= 1;
                            autoTaskBaseList.get(size).setAutoNum(autoTaskBaseList.get(size).getAutoNum() - 1);
                            if (autoTaskBaseList.get(size).getAutoNum() <= 0) {
                                autoTaskBaseList.remove(size);
                            }
                        }
                    }
                }
            }
        }
    }

    //接取任务  寻路  执行任务 任务完成 传送回去  有剩余的任务执行次数 回到第一条
    /**添加脚本*/
    public static void addScript(List<Object> list){
        synchronized (object) {
            script=list;
            isScript=true;
        }
    }
    /**取消脚本*/
    public static void removeScript(){
        synchronized (object) {
            script=null;
            isScript=false;
        }
    }

    public static void stopScript(){
        synchronized (object) {
            isAutoTask=false;
            autoTaskBaseList = null;
        }
        removeScript();
    }


    //1250,1,4020,4160
    public static void autoPassPort(String xyStr) {
        Goodstable goodstable = null;
        int i = 0;
        while (i < GoodsListFromServerUntil.getGoodslist().length) {
            if (GoodsListFromServerUntil.getGoodslist()[i] != null) {
                if (GoodsListFromServerUntil.getGoodslist()[i].getType().longValue() == 2125L) {
                    goodstable = GoodsListFromServerUntil.getGoodslist()[i];
                    break;
                }
            }
            ++i;
        }

        goodstable.setUsetime(Integer.valueOf(goodstable.getUsetime().intValue() - 1));
        GoodsListFromServerUntil.Deletebiaoid11(goodstable.getRgid());
        final String sendmesxx = Agreement.getAgreement().userAgreement(goodstable.getRgid().toString());
        SendMessageUntil.toServer(sendmesxx);
//        WorldMapJpanel.setNumber();

        ZhuFrame.getZhuJpanel().addPrompt2("消耗了【#G任我行】");
        if (xyStr == null || xyStr.length() == 0) {
            ZhuFrame.getZhuJpanel().addPrompt2("未找到目标地址!!!");
        } else {
            String kkf = "传送=" + xyStr + ", 可用次数=10";
            String kkf0 = "传送=" + xyStr;
            String kkf1 = xyStr;
            String[] vs = kkf.split(",");
            String[] cishu = vs[vs.length - 1].split("=");
            int sum = Integer.parseInt(cishu[1]);
            --sum;
            String[] path = null;
            StringBuffer buffer = new StringBuffer();
            if (buffer.length() != 0) {
                buffer.append("|");
            }
            buffer.append(kkf0);
            if (path == null) {
                String[] pathv = kkf1.split(",");
                String wz = pathv[1] + "(" + pathv[2] + "," + pathv[3] + ")";
                path = pathv;
            }
            if (buffer.length() != 0) {
                buffer.append("|");
            }
            buffer.append(cishu[0]);
            buffer.append("=");
            buffer.append(sum);
            if (path != null) {
                if (sum <= 0) {
                    NPCJfram.getNpcJfram().getNpcjpanel().getGood().setUsetime(0);
                }
                GoodsMouslisten.gooduse(NPCJfram.getNpcJfram().getNpcjpanel().getGood(), 2);
                if (sum <= 0) {
                    GoodsListFromServerUntil.Deletebiaoid(NPCJfram.getNpcJfram().getNpcjpanel().getGood().getRgid());
                }
                Door door = new Door();
                door.setDoormap(path[0]);
                door.setDoorpoint(path[2] + "|" + path[3]);

                try {
                    TP.tp(door, 1);
                } catch (Exception var9) {
                    var9.printStackTrace();
                }
            }
        }
    }

    public static boolean mustPassPort(int roleX,int roleY,int mapId,int targetX,int targetY,int targetMapId){
        if (mapId==targetMapId &&Math.abs(roleX-targetX)<200&&Math.abs(roleY-targetY)<200) {
            return false;
        }else return true;
    }

    public static boolean mustPassPort1(int roleX,int roleY,int mapId,int targetX,int targetY,int targetMapId){
        if (mapId==targetMapId &&Math.abs(roleX-targetX)<3000&&Math.abs(roleY-targetY)<3000) {
            return false;
        }else return true;
    }
}
